package servlet;

import pojo.AccessControlDevice;
import service.AccessControlDeviceService;
import service.impl.AccessControlDeviceServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;


@WebServlet(urlPatterns = "/update")
public class UpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置请求的字符编码
        request.setCharacterEncoding("UTF-8");

        //设置响应的字符编码
        response.setCharacterEncoding("UTF-8");

        //设置内容
        response.setContentType("text/html");

        //获取数据
        Integer status = Integer.parseInt(request.getParameter("status"));
        Integer id = Integer.parseInt(request.getParameter("id"));

        AccessControlDeviceService accessControlDeviceService = new AccessControlDeviceServiceImpl();
        Integer update = accessControlDeviceService.update(status, id);

        PrintWriter out = response.getWriter();
        out.print(update);
    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
